package com.bdqn.zhang.action;

import com.bdqn.zhang.pojo.Sysuser;
import com.bdqn.zhang.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

@Controller
public class UserAction extends ActionSupport implements ModelDriven<Sysuser> {

    //此处必须实例化
    private Sysuser user = new Sysuser();


    /*定义集合*/


    @Override
    public Sysuser getModel() {
        return user;
    }

    @Resource
    private UserService userService;


    public String login(){
        Sysuser u = userService.findUser(this.user.getUsername(),this.user.getPassword());
        if(u != null){
            ServletActionContext.getRequest().getSession().setAttribute("username",u.getUsername());
            return "success";
        }
        return "fail";
    }
}


